<template>
	<div class="activitiesNinePro" v-if="productdata.length>0">
		<div class="proul">
			<active-item itemType="C" v-if="moreseedata.relPosition" :moreseedata="moreseedata"></active-item>
			<active-item itemType="G" :buttonActive=" isApp ? buttonActive.bind(this,val) : null " v-for="(val,index) in productdata" :key="index" v-show="productdata.length>0" :detail="val"></active-item>
			<div v-if="goodsInfo.length==0 && env === 'edit'">暂无数据</div>
			<div style="clear: both;"></div>
		</div>
	</div>

</template>

<script>
	import { queryGoodsList } from '@/utils/ReturnAxios';
	import ActiveItem from '../ActiveItem';
	import { ADD_CAR } from "../../config/postMessage-types";
	export default {
		props: {
			goodsInfo: {
				type: Array,
				default: () => []
			}
		},
		data() {
			return {
				codeList: [],
				productdata: [],
				moreseedata: {},
				isOnLoad: true,
			}
		},
		components: {
			ActiveItem
		},
		methods: {
			goodsCodearrey() {
				this.codeList = []
				this.productdata = []
				this.moreseedata = {}
				if(this.goodsInfo.length == 0) {
					return
				}
				if(this.goodsInfo && this.goodsInfo.length > 0) {
					for(var i = 0; i < this.goodsInfo.length; i++) {
						if(this.goodsInfo[i].relPosition == "GOODS") {
							//this.codeList.push(this.goodsInfo[i].goodsCode)
							this.productdata.push(this.goodsInfo[i].goodsNewVO)
						} else if(this.goodsInfo[i].relPosition == "IMAGE") {
							this.moreseedata = this.goodsInfo[i]
						}
					}
					this.getdetaildata()
					//this.queryDetail()
				}
			},
			async queryDetail() {
				this.isOnLoad = true
				var goodscodeList = this.codeList
				if(goodscodeList.length == 0) {
					return
				}
				var config = {
					goodscodeList: goodscodeList
				}
				var res = await queryGoodsList(config)
				res = res.data
				this.productdata = res.data[0]
				this.isOnLoad = false
				this.getdetaildata()
				if(!res.returnCode) {
					return
				}
			},
			getdetaildata() {
				for(var i = 0; i < this.goodsInfo.length; i++) {
					for(var j = 0; j < this.productdata.length; j++) {
						if(this.goodsInfo[i].goodsCode == this.productdata[j].goodsCode) {
							this.productdata[j].mainPic = this.goodsInfo[i].publicityPicture
							this.productdata[j].regularTypeLabel = this.goodsInfo[i].relTitle
						}
					}
				}
			},
			buttonActive(val) {
				//加入购物车
				let titleConfig = JSON.stringify({
					type: ADD_CAR,
					params: {
						page: 'Activity',
						"detailInfo": val,
					}
				});
				window.postMessage(titleConfig);
			}
			
		},
		computed: {
			env() {
				return window.environment; // 获取是否是编辑状态
			},
			isApp() {
				return window.isApp;
			}
		},

		watch: {
			goodsInfo() {
				this.goodsCodearrey()
			},
		},
		mounted() {
			this.goodsCodearrey()
		},
	}
</script>

<style>
	.activitiesNinePro .proul {
		padding: 0.5rem;
		position: relative;
	}
	
	.moresee {
		width: 33.3%;
		float: left;
		height: 8.85rem;
		margin-bottom: 0.5rem;
		line-height: 8rem;
		opacity: 0.7;
		background-position: center;
		background-repeat: no-repeat;
		background-size: cover;
	}
	
	.moresee span {
		font-size: 1rem;
		color: #fff;
	}
</style>